package com.engine.hitech.duss.lefttree.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.hitech.duss.lefttree.service.LeftTreeService;
import com.engine.hitech.duss.lefttree.service.impl.LeftTreeServiceImpl;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

/**
*@Description:
*@Param:
*@return:
*@Author: Dusongsong
*@Date: 2021/3/1
*/


public class WeaLeftTreeWeb {

    private LeftTreeService getService(User user) {
        return ServiceUtil.getService( LeftTreeServiceImpl.class, user);
    }

  /**
  *@Description:
  *@Param: [request, response]
  *@return: java.lang.String
  *@Author: Dusongsong
  *@Date: 2021/3/1
  */
    @GET
    @Path("/getLeftTreeData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getLeftTreeData(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            //获取当前用户
            User user = HrmUserVarify.getUser(request, response);
            apidatas.putAll(getService(user).getLeftTreeData(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

}
